<template>
  <div class="app-container">

    <el-form
      ref="form"
      :model="model"
      label-width="120px"
    >

      <el-form-item hidden="hidden" disabled="disabled" label="id">
        <el-input v-model="model.id" disabled="disabled" />
      </el-form-item>

      <el-form-item label="名称">
        <el-input v-model="model.name" />
      </el-form-item>

      <el-form-item label="路径">
        <el-input v-model="model.uri" />
      </el-form-item>

      <el-form-item label="查询权限">
        <el-switch
          v-model="model.getMethod"
          active-text="开"
          inactive-text="关"
        />
      </el-form-item>

      <el-form-item label="新增权限">
        <el-switch
          v-model="model.postMethod"
          active-text="开"
          inactive-text="关"
        />
      </el-form-item>

      <el-form-item label="删除权限">
        <el-switch
          v-model="model.deleteMethod"
          active-text="开"
          inactive-text="关"
        />
      </el-form-item>

      <el-form-item label="修改权限">
        <el-switch
          v-model="model.putMethod"
          active-text="开"
          inactive-text="关"
        />
      </el-form-item>

      <el-form-item label="备注">
        <el-input v-model="model.remark" type="textarea" />

      </el-form-item>

      <el-form-item v-show="model.createTime" label="创建时间">
        <el-col :span="24">
          <el-date-picker v-model="model.createTime" disabled="disabled" type="datetime" placeholder="请选择一个时间" style="width: 100%;" />
        </el-col>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">{{ action }}</el-button>
        <el-button type="info" @click="back">返回</el-button>
      </el-form-item>

    </el-form>
  </div>
</template>

<script>

import { getOne, createOne, update } from '@/api/system/permission'
export default {
  data() {
    return {
      action: '创建',
      listLoading: true,
      model: {
      }
    }
  },
  async created() {
    const id = this.$route.params.id
    if (!id) {
      return
    }
    this.action = '修改'
    const { data } = await getOne(id)
    this.model = data
    this.listLoading = false
  },
  methods: {
    async onSubmit() {
      console.log(this.model)
      let res
      if (this.model.id) {
        res = await update(this.model).then({})
      } else {
        res = await createOne(this.model).then({})
      }
      if (res.code === 0) {
        this.$message.success('操作成功')
        this.back()
      }
    },
    back() {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>
